package com.glink.manage.controller;

import com.glink.common.exception.GeneralSimpleException;
import com.glink.common.util.LogUtil;
import com.glink.common.vo.ResponseResult;
import com.glink.manage.dto.sip.*;
import com.glink.manage.sip.EquipSipService;
import com.glink.manage.vo.sip.AudioBroadcastResultVO;
import com.glink.manage.vo.sip.NvrStorageVO;
import com.glink.manage.vo.sip.OperatePresetListVO;
import com.glink.manage.vo.sip.RealStreamVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 摄像机相关操作Controller
 *
 * @author xum
 * @since 2024/8/30
 */
@Slf4j
@RestController
@RequestMapping("/API/Manage/sip")
@Api(tags = "摄像机相关操作")
public class SipController extends AbstractBaseController {

    @Autowired
    private EquipSipService equipSipService;

    @ApiOperation(value = "1.ptz控制")
    @PostMapping(value = "/ptz", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<Object> ptzControl(@Validated @RequestBody PTZControlDTO dto)throws GeneralSimpleException  {
        log.info("1.ptz控制：{}", LogUtil.encode(dto));
        equipSipService.ptzControl(dto);
        return this.response(null);
    }

    @ApiOperation(value = "2.点播")
    @PostMapping(value = "/realPlay", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<RealStreamVO> realPlay(HttpServletRequest request, @Validated @RequestBody ProxyCommonDTO dto) throws GeneralSimpleException {
        log.info("2.点播：{}", LogUtil.encode(dto));
        return this.response(equipSipService.realPlay(dto));
    }

    @ApiOperation(value = "3.关闭点播")
    @PostMapping(value = "/realStop", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<Object> realStop(@Validated @RequestBody ProxyCommonDTO dto) throws GeneralSimpleException {
        log.info("3.关闭点播：{}", LogUtil.encode(dto));
        return this.response(equipSipService.realStop(dto));
    }

    @ApiOperation(value = "4.预置位操作")
    @PostMapping(value = "/operatePreset", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<Object> operatePreset(@Validated @RequestBody OperatePresetDTO dto) throws GeneralSimpleException {
        log.info("4.预置位操作：{}", LogUtil.encode(dto));
        equipSipService.operatePreset(dto);
        return this.response(null);
    }

    @ApiOperation(value = "5.获取预置位信息")
    @PostMapping(value = "/getPtzPreset", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<List<OperatePresetListVO>> getPtzPreset(@Validated @RequestBody OperatePresetListDTO dto) throws GeneralSimpleException {
        log.info("5.获取预置位信息：{}", LogUtil.encode(dto));
        return this.response(equipSipService.getPtzPreset(dto));
    }

    @ApiOperation(value = "6.获取NVR存储空间")
    @PostMapping(value = "/findNvrStorageVO", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<NvrStorageVO> findNvrStorageVO(@Validated @RequestBody NvrStorageDTO dto) throws GeneralSimpleException {
        log.info("6.获取NVR存储空间：{}", LogUtil.encode(dto));
        return this.response(equipSipService.findNvrStorageVO(dto));
    }

    @ApiOperation(value = "7.ptz 3d控制")
    @PostMapping(value = "/ptz3d", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<Object> ptzControl3d(@Validated @RequestBody PTZ3dCommandDTO dto)throws GeneralSimpleException {
        log.info("7.ptz 3d控制：{}", LogUtil.encode(dto));
        equipSipService.ptzControl3d(dto);
        return this.response(null);
    }

    @ApiOperation(value = "8.语音广播")
    @PostMapping("/broadcast")
    public ResponseResult<AudioBroadcastResultVO> broadcastApi(@Validated @RequestBody BroadcastDTO dto)throws GeneralSimpleException {
        log.info("8.语音广播：{}", LogUtil.encode(dto));
        return this.response(equipSipService.broadcastApi(dto));
    }
}
